package com.tianya.common.dao;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.springframework.jdbc.core.support.JdbcDaoSupport;

public class BookQueryDao extends JdbcDaoSupport {

	@SuppressWarnings("unchecked")
	public List<Map> Query(String pListNo, String pBid, String pName,
			String pDate, String pBusPlace, String pBusTime, String pType) {

		String sql = "select T_EXPOTICKET.LISTNO,t_books.* from t_books inner join T_EXPOTICKET on t_books.expono=t_expoticket.expono where T_EXPOTICKET.Flag=0 and t_books.FLAG=0 ";
		StringBuffer sb = new StringBuffer();
		ArrayList parms = new ArrayList(0);
		if (StringUtils.isNotEmpty(pListNo)) {
			sb.append(" and T_EXPOTICKET.listno like");
			sb.append(" ?");
			parms.add("%" + pListNo + "%");
		}
		if (StringUtils.isNotEmpty(pBid)) {
			sb.append(" and to_char(t_books.bid) like");
			sb.append(" ?");
			parms.add("%" + pBid + "%");
		}
		if (StringUtils.isNotEmpty(pName)) {
			sb.append(" and t_books.name like");
			sb.append(" ?");
			parms.add("%" + pName + "%");
		}
		if (StringUtils.isNotEmpty(pDate)) {
			sb.append(" and to_char(t_books.sdate) =");
			sb.append(" ?");
			parms.add(pDate.replaceAll("/",""));
		}
		if (!"0".equals(pBusPlace) && StringUtils.isNotEmpty(pBusPlace)) {
			sb.append(" and t_books.BusPlace =");
			sb.append(" ?");
			parms.add(pBusPlace);
		}
		if (!"0".equals(pBusTime) && StringUtils.isNotEmpty(pBusTime)) {
			sb.append(" and t_books.BusTime =");
			sb.append(" ?");
			parms.add(pBusTime);
		}
		if (!"-1".equals(pType) && StringUtils.isNotEmpty(pType)) {
			sb.append(" and to_char(t_books.type) =");
			sb.append(" ?");
			parms.add(pType);
		}
		sql += sb.toString();

		Object[] objs = parms.toArray();
		List<Map> list = this.getJdbcTemplate().queryForList(sql, objs);
		// List<Map> list = this.getJdbcTemplate().queryForList(sql);
		return list;

	}
}
